package com.ssy.lingxi.order.controller.platform;

import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.order.model.vo.basic.request.OrderIdVO;
import com.ssy.lingxi.order.model.vo.platform.request.PlatformConfirmPayPageVO;
import com.ssy.lingxi.order.model.vo.platform.request.PlatformOrderPageVO;
import com.ssy.lingxi.order.model.vo.platform.response.PlatformConfirmPayQueryVO;
import com.ssy.lingxi.order.model.vo.platform.response.PlatformOrderDetailVO;
import com.ssy.lingxi.order.model.vo.platform.response.PlatformOrderQueryVO;
import com.ssy.lingxi.order.model.vo.platform.response.PlatformPageItemVO;
import com.ssy.lingxi.order.model.vo.vendor.request.ConfirmPayVO;
import com.ssy.lingxi.order.service.platform.IPlatformOrderManageService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @menu 平台后台 - 订单管理相关接口
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-29
 */
@RestController
@RequestMapping("/order/platform/manage")
public class PlatformOrderManageController {
    @Resource
    private IPlatformOrderManageService platformOrderManageService;

    /**
     * （订单查询页面）获取前端页面下拉框列表
     * @param headers HttpHeaders信息
     * @return 查询结果
     */
    @RequestMapping(value = "/page/items", method = RequestMethod.GET)
    public Wrapper<PlatformPageItemVO> getPageItems(@RequestHeader HttpHeaders headers) {
        return platformOrderManageService.getPageItems(headers);
    }

    /**
     * 分页查询订单列表
     * @param headers HttpHeaders信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformOrderQueryVO>> pageOrders(@RequestHeader HttpHeaders headers, @Valid PlatformOrderPageVO pageVO) {
        return platformOrderManageService.pageOrders(headers, pageVO);
    }

    /**
     * 查询订单详情
     * @param headers HttpHeaders信息
     * @param idVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public Wrapper<PlatformOrderDetailVO> getOrderDetail(@RequestHeader HttpHeaders headers, @Valid OrderIdVO idVO) {
        return platformOrderManageService.getOrderDetail(headers, idVO);
    }

    /**
     * “待确认支付结果” - 查询订单列表
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/pay/confirm/page", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformConfirmPayQueryVO>> pageToConfirmPayOrders(@RequestHeader HttpHeaders headers, @Valid PlatformConfirmPayPageVO pageVO) {
        return platformOrderManageService.pageToConfirmPayOrders(headers, pageVO);
    }

    /**
     * “待确认支付结果” - 查询订单详情
     * @param headers Http头部信息
     * @param idVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/pay/confirm/detail", method = RequestMethod.GET)
    public Wrapper<PlatformOrderDetailVO> getToConfirmPayOrderDetails(@RequestHeader HttpHeaders headers, @Valid OrderIdVO idVO) {
        return platformOrderManageService.getToConfirmPayOrderDetails(headers, idVO);
    }

    /**
     * “待确认支付结果” - 确认支付结果
     * @param headers Http头部信息
     * @param confirmPayVO 接口参数
     * @return 确认结果
     */
    @RequestMapping(value = "/pay/confirm", method = RequestMethod.POST)
    public Wrapper<Void> confirmOrderPayment(@RequestHeader HttpHeaders headers, @RequestBody @Valid ConfirmPayVO confirmPayVO) {
        return platformOrderManageService.confirmOrderPayment(headers, confirmPayVO);
    }

    /**
     * 导出分页查询订单列表
     * @param token 登录token
     * @param pageVO 接口参数
     * @param response 响应体
     */
    @RequestMapping(value = "/export", method = RequestMethod.GET)
    public void exportOrders(HttpServletResponse response, @Valid PlatformOrderPageVO pageVO, String token) {
        platformOrderManageService.exportOrders(response, pageVO, token);
    }
}
